package com.atguigu.gmall.cart.service.impl;

import com.atguigu.gmall.cart.mapper.CartMapper;
import com.atguigu.gmall.cart.service.CartAsyncService;
import com.atguigu.gmall.model.cart.CartInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class CartAsyncServiceImpl implements CartAsyncService {
    @Autowired
    private CartMapper cartMapper;

    @Async
    public void updateCartInfo(CartInfo cartInfo) {
        log.info("方法开始执行--updateCartInfo-{}" + Thread.currentThread().getName());
        cartMapper.updateById(cartInfo);
    }


    @Async
    public void saveCartInfo(CartInfo cartInfo) {
        log.info("方法开始执行--saveCartInfo-{}" + Thread.currentThread().getName());
        cartMapper.insert(cartInfo);
    }

    @Async
    public void checkCart(Long skuId, Integer isCkecked,String userId) {
        CartInfo cartInfo = new CartInfo();
        cartInfo.setIsChecked(isCkecked);
        cartMapper.update(cartInfo,new QueryWrapper<CartInfo>().
                eq("sku_id",skuId).eq("user_id",userId));
    }

}
